<template>
  <div class="c-flex-row c-pb24" v-if="!isFromM7">
    <div class="c-ww180 c-hh120 c-flex-shrink0 c-text-hidden c-p c-br10" :class="cfg && cfg.isCopyPicture == 0 ? 'closeBig' : 'aCloseBig'">
      <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="$addXossFilter(item.courseAvatar, require('../../assets/defult270.png'))" />
      <div class="c-pa c-p-b8 c-p-r8 c-br8 c-fs18 c-fc-white c-ph5 c-hh28 c-flex-row c-flex-center c-translucent-balck50">
        {{courseTypeObj[item.courseType]}}
      </div>
      <vip-status :item="item"></vip-status>
    </div>
    <div class="c-flex-row c-flex-column c-pl20 c-flex-1 c-justify-sb c-w0">
      <div class="c-fs24 c-lh34 c-text-ellipsis1 c-fc-xblack">
        <span v-if="item.isSaleOut == 0" class="c-mr6 c-fs20 c-fc-white c-ph4 c-br-tr10 c-br-bl10 c-bg-ccc">已停售</span>{{item.name}}
      </div>
      <div v-if="item.lecturer">
        <span class="iconfont icon-geren1 c-fc-sblack c-fs18 c-inlineblack c-vcAlign-middle"></span>
        <span class="c-wlecturer c-fs18 c-lh26 c-text-ellipsis1 c-textAlign-c c-br4 c-inlineblack c-vcAlign-middle c-maxw50">{{item.lecturer}}</span>
      </div>
      <div class="c-fs20 c-fc-gray" v-if="(item.courseType == 0 || item.courseType == 1) && item.previewLabel">{{item.courseType == 0 ? '支持试看' : '支持试听'}}</div>
      <div class="theme-fc c-flex-row" :class="item.payType == 1 ? 'c-fs24' : 'c-fs30'">
        <div class="c-flex-shrink0 c-flex-row c-aligni-center" :class="item.payType == 1 ? 'c-lh24' : 'c-lh32'">
          <div class="c-flex-row c-aligni-end c-pr10">
            <span class="c-fc-xmlred c-fs0">
              <span class="c-fs20 c-fw600"v-if="item.payType == 2">{{'￥' | iosPriceFilter}}</span>
              <span class="c-fw600" :class="checkCnPrice(item.payType, item.price, 5) ? 'c-fs22' : 'c-fs26'">{{item.payType | priceValueFilter(item.price, 5, item.optimal, 'index')}}</span>
              <span v-if="isShowcrossedPrice(item)" class="c-fs24 c-fc-gray c-text-decoration-through c-mh4">￥{{getCrossedPrice(item)}}</span>
            </span>
          </div>
        </div>
        <div v-if="enableShowModuleView == 1 || !(enableHiddenModules && enableHiddenModules.includes(ckFrom))" class="c-flex-grow1 c-w0 c-textAlign-r">
          <span class="c-flex-grow1 c-fs20 c-lh28 c-w0 c-textAlign-r c-fc-gray">{{item.plays | formatNumber}}人{{item.courseType == 1 ? '收听' : '看过'}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js"
import vipStatus from '@/components/templates/common/vipStatus.vue'
import CoverImg from '@/components/templates/common/coverImg.vue';
export default {
  name: "CourseItem",
  components: {
    vipStatus,
    CoverImg
  },
  //props: ["item"],
  props: {
    item: {
      type: Object,
      default: null,
    },
    isFromM7: {
      type: Boolean,
      default: false
    },
    itemType: {
      type: Number,
      default: 1//1一行一列，2一行两列，3一行三列
    },
    itemList: {
      type: Array,
      default: () => []
    },
    showCount: {
      type: Number,
      default: 1
    },
    showMore: {
      type: Number,
      default: 0,
    },
    visible:{
      type: Object,
      default: () => {
        return {
          priceVisible:true, // 价格、商品价格
          originalPriceVisible:true, // 划线价格(营销活动的划线价格，划线的是产品没参加营销活动时的购买价)
          crossedPriceVisible:true, // 划线价格（产品的划线价格，只作展示，不作为售卖价）
          dataVisible:true, // 商品数据、数据字段、数据
          statusVisible:true, // 状态
          forecastVisible:true, // 预告时间
          qrVisible:true, // 预告二维码
          vipVisible:true, // vip角标
        }
      },
    }
  },
  data() {
    return {
      courseTypeObj: {
        0: '视频',
        1: '音频',
        2: '图文',
      },
      cfg: JSON.parse(localStorage.getItem("cfg")),
      ckFrom: global.ckFrom.course,
      enableShowModuleView: localStorage.getItem("cfg") ? JSON.parse(localStorage.getItem("cfg")).enableShowModuleView : 1,
      enableHiddenModules: localStorage.getItem("cfg") ? JSON.parse(localStorage.getItem("cfg")).enableHiddenModules : [],
    };
  },
  computed: {
    // 判断显示划线价格
    isShowcrossedPrice() {
      return function(item) {
        return !this.$isWxAppIos() && item.crossedPrice && Number(item.crossedPrice) > 0;
      }
    },
    // 获取划线价格
    getCrossedPrice() {
      return function(item) {
        return item.crossedPrice;
      }
    }
  },
  methods: {
    checkCnPrice(payType, price, prodType) {
      return utilJs.checkCnPrice(payType, price, prodType)
    },
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.icon-course-mark {
  position: absolute;
  bottom: 0;
  right: 0.2rem;
  width: 0.9rem;
  height: 0.9rem;
}
.icon-course-mark1 {
  position: absolute;
  bottom: 0;
  right: 0.2rem;
  width: 0.9rem;
  height: 0.9rem;
}
.classify-sign {
  position: absolute;
  bottom: 0.2rem;
  right: 0.2rem;
  background: #333;
  border: 1px solid #fff;
  border-radius: 50%;
  width: 0.9rem;
  height: 0.9rem;
  overflow: hidden;
}
.trim-sign {
  line-height: 0.8rem;
}
.classify-sign > i {
  margin-left: -0.03rem;
}
.vipStatus {
  position: absolute;
  top: 0;
  left: 0;
  width: 1.5rem;
  height: 1.5rem;
}
.c-ww110 {
  width: 2.75rem;
}
.c-hh44 {
  height: 1.1rem;
}
.c-mtauto {
  margin-top: auto;
}
.c-pv2 {
  padding-top: 0.05rem;
  padding-bottom: 0.05rem;
}
.c-tag-br12 {
  border-radius: 0.3rem 0 0.3rem 0;
}
</style>
